package com.hobobe.tailor.common.util;

import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.Logger;

public class ConfigFactory {

	private static final Logger log = Logger.getLogger(ConfigFactory.class);
	
	private static Properties emailConfig = null;
	private static Properties propertyConfig = null;
	static {
		InputStream emailInputStream = null;
		InputStream propertyInputStream = null;
		ClassLoader classLoader = Thread.currentThread()
				.getContextClassLoader();
		try {
			//加载邮箱信息
			emailConfig = new Properties();
			emailInputStream = classLoader.getResourceAsStream("conf/email.properties");
			emailConfig.load(emailInputStream);
			
			//支付属性文件信息
			propertyConfig = new Properties();
			propertyInputStream = classLoader.getResourceAsStream("conf/property.properties");
			propertyConfig.load(propertyInputStream);
		} catch (Exception e) {
			log.error("ConfigFactory init error", e);
		} finally {
			if (emailInputStream != null) {
				try {
					emailInputStream.close();
				} catch (Exception e) {
					log.error("ConfigFactory close InputStream error",
							e);
				}
			}
			if (propertyInputStream != null) {
				try {
					propertyInputStream.close();
				} catch (Exception e) {
					log.error("ConfigFactory close InputStream error",
							e);
				}
			}
		}
	}
	
	public static Properties getEmailConfig() {
		return emailConfig;
	}
	
	public static Properties getPropertyConfig(){
		return propertyConfig;
	}
	
}
